home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / lapbtime.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  3KB  |  143 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "config.h"
  4. #include "mbuf.h"
  5. #include "ax25.h"
  6. #include "timer.h"
  7. #include "netuser.h"
  8. #include "session.h"
  9. #include "ftp.h"
  10. #include "telnet.h"
  11. #include "iface.h"
  12. #include "finger.h"
  13. #include "lapb.h"
  14.  
  15. /* Called whenever timer T1 expires */
  16. void
  17. recover(n)
  18. int *n;
  19. {
  20.     register struct ax25_cb *axp;
  21.     void lapbstate();
  22.  
  23.     axp = (struct ax25_cb *)n;
  24.  
  25.     switch(axp->state){
  26.     case SETUP:
  27.         if(axp->n2 != 0 && axp->retries == axp->n2){
  28.             free_q(&axp->txq);
  29.             lapbstate(axp,DISCONNECTED);
  30.         } else {
  31.             axp->retries++;
  32.             sendctl(axp,COMMAND,SABM|PF);
  33.             start_timer(&axp->t1);
  34.         }
  35.         break;
  36.     case DISCPENDING:
  37.         if(axp->n2 != 0 && axp->retries == axp->n2){
  38.             lapbstate(axp,DISCONNECTED);
  39.         } else {
  40.             axp->retries++;
  41.             sendctl(axp,COMMAND,DISC|PF);
  42.             start_timer(&axp->t1);
  43.         }
  44.         break;
  45.     case CONNECTED:
  46.         axp->retries = 0;
  47.     case RECOVERY:    /* note fall-thru */
  48.         if(axp->n2 != 0 && axp->retries == axp->n2){
  49.             /* Give up */
  50.             sendctl(axp,RESPONSE,DM|PF);
  51.             free_q(&axp->txq);
  52.             lapbstate(axp,DISCONNECTED);
  53.         } else {
  54.             /* Transmit poll */
  55.             tx_enq(axp);
  56.             axp->retries++;
  57.             lapbstate(axp,RECOVERY);
  58.         }
  59.         break;
  60.     case FRAMEREJECT:
  61.         if(axp->n2 != 0 && axp->retries == axp->n2){
  62.             sendctl(axp,RESPONSE,DM|PF);
  63.             free_q(&axp->txq);
  64.             lapbstate(axp,DISCONNECTED);
  65.         } else {
  66.             frmr(axp,0,0);    /* Retransmit last FRMR */
  67.             start_timer(&axp->t1);
  68.             axp->retries++;
  69.         }
  70.         break;
  71.     }
  72.     /* Empty the trash */
  73.     if(axp->state == DISCONNECTED)
  74.         del_ax25(axp);
  75. }
  76.  
  77. /* T2 has expired, we can't delay an acknowledgement any further */
  78. void
  79. send_ack(n)
  80. int *n;
  81. {
  82.     char control;
  83.     register struct ax25_cb *axp;
  84.  
  85.     axp = (struct ax25_cb *)n;
  86.     switch(axp->state){
  87.     case CONNECTED:
  88.     case RECOVERY:
  89.         control = len_mbuf(axp->rxq) > axp->window ? RNR : RR;
  90.         sendctl(axp,RESPONSE,control);
  91.         axp->response = 0;
  92.         break;
  93.     }
  94. }
  95.  
  96. /* Send a poll (S-frame command with the poll bit set) */
  97. void
  98. pollthem(n)
  99. int *n;
  100. {
  101.     register struct ax25_cb *axp;
  102.  
  103.     axp = (struct ax25_cb *)n;
  104.     if(axp->proto == V1)
  105.         return;    /* Not supported in the old protocol */
  106.     switch(axp->state){
  107.     case CONNECTED:
  108.         axp->retries = 0;
  109.         tx_enq(axp);
  110.         lapbstate(axp,RECOVERY);
  111.         break;
  112.     }
  113. }
  114. /* Transmit query */
  115. tx_enq(axp)
  116. register struct ax25_cb *axp;
  117. {
  118.     char ctl;
  119.     struct mbuf *bp;
  120.  
  121.     /* I believe that retransmitting the oldest unacked
  122.      * I-frame tends to give better performance than polling,
  123.      * as long as the frame isn't too "large", because
  124.      * chances are that the I frame got lost anyway.
  125.      * This is an option in LAPB, but not in the official AX.25.
  126.      */
  127.     if(axp->txq != NULLBUF && len_mbuf(axp->txq) < axp->pthresh
  128.      && (axp->proto == V1 || !axp->remotebusy)){
  129.         /* Retransmit oldest unacked I-frame */
  130.         dup_p(&bp,axp->txq,0,len_mbuf(axp->txq));
  131.         ctl = PF | I | ((axp->vs - axp->unack) & MMASK) << 1
  132.          | axp->vr << 5;
  133.         sendframe(axp,COMMAND,ctl,bp);
  134.     } else {
  135.         ctl = len_mbuf(axp->rxq) >= axp->window ? RNR|PF : RR|PF;    
  136.         sendctl(axp,COMMAND,ctl);
  137.     }
  138.     axp->response = 0;    
  139.     stop_timer(&axp->t3);
  140.     start_timer(&axp->t1);
  141. }
  142.  
  143.